package com.lwm.annotationandreflection.ref;

/**
 * @author liweimin
 * @date 2020/9/24 11:25
 * @description 得到class类
 */
public class ref02 {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        System.out.println("这个人是："+person.getName());
        //通过对象获得
        Class clazz1 = person.getClass();
        System.out.println(clazz1.hashCode());
        //通过forname获得
        Class clazz2 = Class.forName("com.lwm.annotationandreflection.ref.Student");
        System.out.println(clazz2.hashCode());
        //通过类名.class获得
        Class clazz3 = Student.class;
        System.out.println(clazz3.hashCode());
        //基本内置对象的包装类都有一个TYPE属性
        Class type = Integer.TYPE;
        System.out.println(type);
        //获得父类类型
        System.out.println(clazz1.getSuperclass());
        System.out.println(clazz1.getName());
        System.out.println(clazz1.getClassLoader());
        //可以使用ClassLoader
        //TODO

    }
}
class Person{
    public String name;

    public Person(String name) {
        this.name = name;
    }

    public Person() {
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
class Student extends Person{
    public Student(String name) {
        super(name);
    }

    public Student() {
        this.name = "学生";
    }
}
class Teacher extends Person{
    public Teacher(String name) {
        super(name);
    }

    public Teacher() {
        this.name = "老师";
    }
}
